package cn.cdeden.system.controller.system;


import cn.cdeden.common.core.domain.R;
import cn.cdeden.common.satoken.utils.LoginHelper;
import cn.cdeden.common.web.core.BaseController;
import cn.cdeden.knowledge.api.domain.RemoteResourceFollowService;
import cn.cdeden.knowledge.api.domain.RemoteResourceService;
import cn.cdeden.knowledge.api.domain.vo.RemoteResourceTypeVo;
import cn.cdeden.knowledge.api.domain.vo.RemoteResourceVo;
import cn.cdeden.resource.api.RemoteFileService;
import cn.cdeden.system.api.model.LoginUser;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/sysResource")
public class SysResourceController extends BaseController{
    @DubboReference
    private RemoteResourceService remoteResourceService;

    @DubboReference
    private RemoteResourceFollowService remoteResourceFollowService;

    @PostMapping
//    @Log("新增日历资源")
//    @ApiOperation("新增日历资源")
    public R create(@Validated @RequestBody RemoteResourceVo resources){
        LoginUser loginUser = LoginHelper.getLoginUser();
        resources.setCreateBy(loginUser.getUserId());
        return R.ok(remoteResourceService.insert(resources));
    }

    @PutMapping
//    @Log("修改日历资源")
//    @ApiOperation("修改日历资源")
    public R update(@Validated @RequestBody RemoteResourceVo resources){
        return R.ok(remoteResourceService.updateById(resources));
    }

    @DeleteMapping
//    @Log("删除日历资源")
//    @ApiOperation("删除日历资源")
    @Transactional
    public R delete(@RequestBody Set<Long> ids) {
        remoteResourceFollowService.remove(ids);
        return R.ok(remoteResourceService.deleteByIds(ids));
    }
}
